﻿using System.Linq;

namespace net.entity.framework.query {
    public class DeleteBuilder : BaseBuilder {
        #region Members

        protected readonly QueryState queryState;

        #endregion

        #region Properties

        public QueryState QueryState {
            get { return queryState; }
        }

        #endregion

        #region Constructors

        protected DeleteBuilder(QueryRoot deleteRoot, QueryClause whereClause)
            : base(false, -1, new[] {deleteRoot}, null, whereClause, Terminal.EmptyTerminals, null,
                   Terminal.EmptyTerminals) {}

        #endregion

        #region Builders

        /// <summary>
        /// Adds where
        /// </summary>
        public class BuilderBottom : DeleteBuilder {
            public BuilderBottom(QueryRoot newDeleteRoot)
                : base(newDeleteRoot, BooleanConstant.True) {}

            public DeleteBuilder Where(QueryClause newWhereQueryClause) {
                return new DeleteBuilder(queryState.SelectRoots.First(), newWhereQueryClause);
            }
        }

        #endregion

        public QueryContext GetQueryContext() {
            return new QueryContext(queryState);
        }

        protected override QueryCompiler GetCompiler() {
            return new DeleteQueryCompiler(QueryState);
        }
    }
}